﻿using System;
using System.IO;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;

class Program
{
    static async Task Main()
    {
        var filePath = @"D:\nako\pdf\somepdf\期刊\sci2.pdf";
        using var client = new HttpClient();
        using var formData = new MultipartFormDataContent();
        // 读取PDF文件内容
        var f = File.OpenRead(filePath);
        var size = f.Length;
        var name = Path.GetFileName(f.Name);
        var strToHash = name.Length * 10 + size;
        var hash = strToHash.GetHashCode();
        f.Close();
        var fileBytes = await File.ReadAllBytesAsync(filePath);
        var url = $"https://localhost:7213/pdf2/html/{hash}";
        // 创建一个文件内容
        var fileContent = new ByteArrayContent(fileBytes);
        fileContent.Headers.ContentDisposition = new System.Net.Http.Headers.ContentDispositionHeaderValue("form-data")
        {
            Name = "file",
            FileName = Path.GetFileName(filePath)
        };

        // 添加文件内容到表单数据
        formData.Add(fileContent);
        client.DefaultRequestHeaders.Add("Authorization",$"dashboard-sk-7320472309");
        // 发送POST请求
        var response = await client.PostAsync(url, formData);
        var str = await response.Content.ReadAsStreamAsync();
        var bytes = new byte[1024];
        var byteRead = 0;
        while ((byteRead = await str.ReadAsync(bytes, 0, 1024)) > 0)
        {
            Console.WriteLine(Encoding.UTF8.GetString(bytes,0,byteRead));
        }

    }
}